<template>
	<view class="l_pages">
		<jnavbar :title="'订单评价'"></jnavbar>
		<scroll-view class="page_container" scroll-y>
			<view class="nav uni-flex-row uni-flex-title">
				<view><text class="lg-font">订单评价</text></view>
				<text class="lg-font" @click="evaluate">发布</text>
			</view>
			<view class="box"></view>
			<view class="evaluate" v-for="(item, i) in list" :key="i">
				<view class="header uni-flex-row">
					<vimage class="img_box" :src="item.master" mode=""></vimage>
					<view class="uni-flex-column">
						<text class="lg-font u-line-2">{{ item.name }}</text>
						<text class="sm-font">{{ item.pvs_value||'' }}</text>
					</view>
				</view>
				<view class="uni-flex-row scorediv">
					<text class="lg-font">评分</text>
					<uni-rate :size="20" :margin="6" v-model="item.score" :allowHalf="true" />
					<text class="sm-font" v-if="item.score <= 2">很差</text>
					<text class="sm-font" v-else-if="item.score > 2 && item.score < 4">一般</text>
					<text class="sm-font" v-else>很好</text>
				</view>
			
				<view class="content">
					<textarea v-model="item.content" placeholder="写点啥吧"></textarea>
					<uploadimg  @getimg="getimg($event, item)"></uploadimg>
				</view>
			</view>
		</scroll-view>
		
	</view>
</template>

<script>
import uploadimg from '@/components/upload/upload.vue';
import http from '@/common/http.js';

export default {
	onShareAppMessage() {
		return this.wxShare();
	},
	data() {
		return {
			imglist: ['sss'],
			list: []
		};
	},
	components: {
		uploadimg
	},
	async onLoad(e) {
		await this.$getWx
		this.id = e.id;
		if (e.id) {
			this.getdetail(e.id);
		}
	},
	methods: {
		getimg(imglist, item) {
			item.img_urls = imglist;
		},
		//订单详情
		getdetail(id) {
			http('/order/readOrder/' + id, {}, 'GET').then(res => {
				if (res.statusCode == 200) {
					let orderdetail = res.data.msg;
					let orderCommodity = orderdetail.order_commodity;
					let list = [];
					orderCommodity.forEach(a => {
						if (a.status == 7) {
							list.push({
								img_urls: [],
								pvs_value:a.sku? a.sku.pvs_value:'',
								name: a.commodity.name,
								master: a.commodity.master,
								id: a.commodity_id,
								content: '',
								ocid: a.order_id,
								score: 5
							});
						}
					});
					this.list = list;
				}
			});
		},
		evaluate() {
			let evaluate = [];
			this.list.forEach(a => {
				evaluate.push({
					commodity_id: a.id,
					img_urls: a.img_urls,
					content: a.content,
					score: a.score * 2,
					ocid: a.ocid
				});
			});
			// #ifdef MP-WEIXIN
			let source = 1;
			// #endif
			// #ifdef H5
			let source = 2;
			// #endif
			let data = {
				id: this.id,
				evaluate: JSON.stringify(evaluate),
				source: source
			};
			http('/order/evaluate', data, 'POST').then(res => {
				if (res.statusCode == 200) {
					uni.navigateBack({});
				} else {
					uni.showToast({
						title: res.data.error_msg,
						icon: 'none'
					});
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.nav {
	width: 750rpx;
	box-sizing: border-box;
	padding: 15rpx 30rpx;
	background: #f4f4f4;
	position: absolute;
	top: 0;
	left: 0;
	z-index: 1;
}
.box {
	width: 750rpx;
	height: 80rpx;
}
.evaluate {
	background: #fff;
	border-radius: 20rpx;
	width: 720rpx;
	margin-left: 15rpx;
	margin-bottom: 20rpx;
	.header {
		padding: 15rpx;
		.img_box {
			width: 80rpx;
			height: 80rpx;
			background: #f0ad4e;
			border-radius: 6rpx;
			margin-right: 15rpx;
		}
	}
	.scorediv {
		// margin-top: 15rpx;
		// font-size: 24rpx;
		padding: 15rpx;
		text:first-child {
			margin-right: 15rpx;
		}
		text:last-child {
			margin-left: 15rpx;
		}
	}
	.content {
		padding: 15rpx;
	}
}
</style>
